package com.sky.controller.admin;

import com.sky.mqtt.MQTTGetaway;
import com.sky.mqtt.MQTTProperties;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Content:
 * @Author: LS
 * @Date: 2023/10/13 11:33
 */
@RestController
@RequestMapping("/admin/mqtt")
@Api(tags = "MQTT")
@Slf4j
public class MQTTController {

    @Autowired
    private MQTTGetaway mqttGetaway;
    @Autowired
    private MQTTProperties mqttProperties;

    @GetMapping("/send/{qos}")
    @ApiOperation("发送MQTT消息")
    public Result sendMessage(@PathVariable Integer qos){
        mqttGetaway.sendToMqtt(mqttProperties.getDefaultTopic(),qos,"defaultTopic:Qos:1");
        return Result.success("已发送");
    }

    @GetMapping("/sendMessage")
    @ApiOperation("发送指定消息")
    public Result sendMessage(String topic,String message,Integer qos){
        mqttGetaway.sendToMqtt(topic,qos,message);
        return Result.success("已发送");
    }
}
